import socket

# 创建一个基于IPV4与TCP协议的socket实例
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 设置阻塞操作如connect(), send(), recv()等的最大等待时间为5秒
client_socket.settimeout(5)

try:
    client_socket.connect(('example.com', 80))
except socket.timeout:
    print('Connection attempt timed out')
finally:
    client_socket.close()

from elasticsearch import Elasticsearch

es = Elasticsearch()

response = es.search(
    index="my_index",
    body={"query": {"match_all": {}}},
    request_timeout=30  # 单位为秒
)

while True:
    msg = input(">>: ").strip()
    if len(msg) == 0:
        continue  # 忽略空白输入并提示重新输入信息
    
    break  # 合法输入则退出循环进行下一步骤